<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
      YouTube Chromeless Player
    </title>
    <script src="swfobject/swfobject.js" type="text/javascript"></script>
    <style type="text/css">

    body {
      font-family: verdana, helvetica;
      background-color: white;
	  border:0;margin:0;
    }

    #timedisplay {
      border: solid 1px red;
      width: 50px;
    }
    </style>

<script type="text/javascript"> 	

var ytplayer;

function onYouTubePlayerReady(playerId) {
      ytplayer = document.getElementById("myytplayer");
    }

var videoId;
var youtubeStorage = "youtubeChromeless";
var youtubeVideoId;

function load() 
{
	var dctk = connected.toolkit;
	var storage = connected.openStorage(youtubeStorage,true);
		videoId = storage.get(youtubeVideoId,videoId);
		connected.debug.print(videoId);
		connected.onKeyEvent = keyHandler;

	var height = connected.outputHeight;
	var width = connected.outputWidth;


	if (width/height >= 16/9) {
		var content = "<object width=\"640\" height=\"385\" id=\"myytplayer\" name=\"myytplayer\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+videoId+"&hl=en&fs=1&autoplay=1&ap=%2526fmt%3D18&rel=0&enablejsapi=1&playerapiid=ytplayer&loop=0\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowScriptAccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/"+videoId+"&hl=en&fs=1&autoplay=1&ap=%2526fmt%3D18&rel=0&enablejsapi=1&playerapiid=ytplayer&loop=0\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"640\" height=\"385\"></embed></object>";
		document.getElementById('player').innerHTML = content;
	        }
	else if (width/height <= 4/3) {
		var content = "<object width=\"480\" height=\"385\" id=\"myytplayer\" name=\"myytplayer\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+videoId+"&hl=en&fs=1&autoplay=1&ap=%2526fmt%3D18&rel=0&enablejsapi=1&playerapiid=ytplayer&loop=0\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowScriptAccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/"+videoId+"&hl=en&fs=1&autoplay=1&ap=%2526fmt%3D18&rel=0&enablejsapi=1&playerapiid=ytplayer&loop=0\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"480\" height=\"385\"></embed></object>";
		document.getElementById('player').innerHTML = content;
	        }
}


function keyHandler(e){
	var keyCode;
	
	if (window.event) {
		keyCode = e.KeyCode;
	}
	else 
		if (e.which) {
			keyCode = e.which;
		}
	
	switch (keyCode) {

		// Enter key 
		case 13:
			function play() {
			  if (ytplayer) {
			    ytplayer.playVideo();
			  }
			}

			connected.debug.print("Pause/Play!");
			break;
	}
}

</script>

  </head>
  <body onLoad="load();" onkeydown="keyHandler(event);" bgcolor="#000000;">
<div style="height:360px;overflow:hidden;" id="player">
    <!-- embed the player -->
You must have the Flash Player installed on your DivX Connected server...
</div>
  </body>
</html>
